import Vue from 'vue'
import App from './App'
import router from './router'
// 导入 element-ui 组件
// import ElementUI from 'element-ui'
// 导入 axios 组件
import axios from 'axios'
// 导入 图标库的 css样式表
import './assets/fonts/iconfont.css'
// 导入 全局的自定义样式表
import './assets/css/global.css'
// 导入 vue-table-with-tree-grid组件
import TableTree from 'vue-table-with-tree-grid'
// 导入nprogress相关js包和css样式
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 导入配置文件
import config from './config.json'

import {
  Pagination,
  Dialog,
  Menu,
  Submenu,
  MenuItem,
  Input,
  Checkbox,
  CheckboxGroup,
  Switch,
  Select,
  Option,
  Button,
  Table,
  TableColumn,
  Tooltip,
  Breadcrumb,
  BreadcrumbItem,
  Form,
  FormItem,
  Tabs,
  TabPane,
  Tag,
  Tree,
  Alert,
  Icon,
  Row,
  Col,
  Upload,
  Card,
  Steps,
  Step,
  Cascader,
  Container,
  Header,
  Aside,
  Main,
  MessageBox,
  Message
} from 'element-ui'

Vue.use(Pagination)
Vue.use(Dialog)
Vue.use(Menu)
Vue.use(Submenu)
Vue.use(MenuItem)
Vue.use(Input)
Vue.use(Checkbox)
Vue.use(CheckboxGroup)
Vue.use(Switch)
Vue.use(Select)
Vue.use(Option)
Vue.use(Button)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Tooltip)
Vue.use(Breadcrumb)
Vue.use(BreadcrumbItem)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Tabs)
Vue.use(TabPane)
Vue.use(Tag)
Vue.use(Tree)
Vue.use(Alert)
Vue.use(Icon)
Vue.use(Row)
Vue.use(Col)
Vue.use(Upload)
Vue.use(Card)
Vue.use(Steps)
Vue.use(Step)
Vue.use(Cascader)
Vue.use(Container)
Vue.use(Header)
Vue.use(Aside)
Vue.use(Main)

Vue.prototype.$confirm = MessageBox.confirm
Vue.prototype.$message = Message

// 把element-ui 组件安装给Vue
// Vue.use(ElementUI)

// 把 vue-table-with-tree-grid安装给Vue
Vue.component('table-tree', TableTree)

// 配置axios
// axios.defaults.baseURL = 'https://www.liulongbin.top:8888/api/private/v1/'
axios.defaults.baseURL = config.baseURL

// 拦截器，给 axios 设置 Authorization 的token信息
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 设置nprogress请求进度条效果
  NProgress.start()
  return config
})

axios.interceptors.response.use(function(response) {
  // Do something with response data
  // 设置nprogress请求进度条效果
  NProgress.done()
  return response
})

Vue.prototype.$http = axios

Vue.config.productionTip = false

// 创建filter过滤器
Vue.filter('dateFormat', function(val) {
  var dt = new Date(val)
  var yy = dt.getFullYear()
  var mm = (dt.getMonth() + 1 + '').padStart(2, 0)
  var dd = (dt.getDate() + '').padStart(2, 0)

  var hh = (dt.getHours() + '').padStart(2, 0)
  var ii = (dt.getMinutes() + '').padStart(2, 0)
  var ss = (dt.getSeconds() + '').padStart(2, 0)
  return `${yy}-${mm}-${dd} ${hh}:${ii}:${ss}`
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
